package com.acoreful.menos.utils;

import java.util.Locale;
import java.util.ResourceBundle;

/**
 * <h3>读取properties</h3>
 * 自动刷新资源文件 
 *
 */
public class PropertiesHelper {
	private final static MyResourceBundleControl ctl = new MyResourceBundleControl(); 
	//private static Properties properties;
	
	private static ResourceBundle getBundle() {  
        return ResourceBundle.getBundle("res", Locale.getDefault(), ctl);  
    }
	public static void main(String[] args) throws InterruptedException {
		System.out.println(getBundle().getString("cancelKey"));  
        Thread.sleep(5000);  
        System.out.println(getBundle().getString("cancelKey"));
	}
	
	/** 
     * 重载控制器 
     */  
    private static class MyResourceBundleControl extends ResourceBundle.Control {  
  
        @Override  
        public long getTimeToLive(String baseName, Locale locale) {  
            return 1000;  
        }  
  
        @Override  
        public boolean needsReload(String baseName, Locale locale,  
                String format, ClassLoader loader, ResourceBundle bundle,  
                long loadTime) {  
            return true;  
        }
    }
}
